package com.sdw.sml.service.service;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.sdw.sml.service.thriftgen.demo.HelloWorldService;

public class HelloTSimpleServerDemo {

	public static final int SERVER_PORT = 8090;

	public void startServer() {
		System.out.println("HelloWorld TSimpleServer start ...");

		try {
			TProcessor tprocessor = new HelloWorldService.Processor<HelloWorldService.Iface>(
					new HelloWorldImpl());

			TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
			TServer.Args tArgs = new TServer.Args(serverTransport);
			tArgs.processor(tprocessor);
			tArgs.protocolFactory(new TBinaryProtocol.Factory());

			TServer server = new TSimpleServer(tArgs);

			server.serve();
		} catch (TTransportException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		HelloTSimpleServerDemo server = new HelloTSimpleServerDemo();
		server.startServer();
	}

}
